from django.contrib.auth import authenticate
from userapp.models import User
from django.contrib.auth.hashers import check_password

class EmailBackend:

    def authenticate(self,request,username=None,password=None):
        user = User.objects.filter(email=username).first()
        if user and check_password(password,user.password):
            return user
        else:
            return None


class PhoneBackend:

    def authenticate(self,request,username=None,password=None):
        user = User.objects.filter(phone=username).first()
        if user and check_password(password,user.password):
            return user
        else:
            return None